var code = "";
if (window.location.href.indexOf("code") != -1) {
    code = window.location.href.split("code=")[1].split("&state")[0];
}
$.ajax({
    url: Feng.ctxPath + "/integralMallWeixin/getMemberRecommendation",
    type: "POST",
    data: {"code": code},
    success: function (data) {
        var html = "";
        html += "<div class=\"medicalRecords\" style=\"height: 100%;font-size: 16px;\">\n" +
            "    <div class=\"integralMallHeadTop\">\n" +
            "        <div style=\"text-align: left\" onclick=\"goBackPersonalCenter()\"><span\n" +
            "                class=\"glyphicon glyphicon-menu-left\"></span></div>\n" +
            "        <div>推荐人</div>\n" +
            "        <div></div>\n" +
            "    </div>\n" +
            "    <div id=\"aaa\" style=\"padding: 10px 10px 46px;height: calc(100% - 45px);overflow: auto;\">\n";
        if (data == '' || data == null) {
            html = "  <div><span class='glyphicon glyphicon-book'>请输入推荐人姓名：</span><input id=\"recommendationName\" class='form-control' value=\"\"></div>\n" +
                "  <div><span class='glyphicon glyphicon-book'>请输入推荐人电话：</span><input id=\"recommendationPhone\" class='form-control' value=\"\"></div>";
            html += " </div>\n" +
                "    <div class=\"integralMallFoot\">\n" +
                "        <button class=\"btn btn-primary btn-lg btn-block\" onclick=\"sureRecommendation()\" type=\"button\">确定</button>\n" +
                "        <button class=\"btn btn-primary btn-lg btn-block\" onclick=\"goBackPersonalCenter()\" type=\"button\">返回</button>\n" +
                "    </div>\n" +
                "</div>";
        } else {
            html += "<div class=\"alreadyRecommendation\">\n" +
                "                        <div style=\"margin-bottom:8px;border-bottom: 1px solid white;\">\n" +
                "                        <span  style=\"background:  white;color:  #ff9700;border-radius:  5px;padding:  3px  8px;margin-left:  10px;\">" + data.startTimes + " " + data.endTimes + "</span>\n" +
                "                        </div>\n" +
                "                        <div><span>推荐人姓名：</span><span>" + data.recommendationName + "</span></div>\n" +
                "                    <div><span>推荐人电话：</span><span>" + data.recommendationPhone + "</span></div>\n" +
                "                    </div>";
            html += " </div>\n" +
                "    <div class=\"integralMallFoot\">\n" +
                "        <button class=\"btn btn-primary btn-lg btn-block\" onclick=\"goBackPersonalCenter()\" type=\"button\">返回</button>\n" +
                "    </div>\n" +
                "</div>";
        }
        $("#memberRecommendationRd").html(html);
    },
    error: function (data) {

    }
});

sureRecommendation = function () {
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/sureRecommendation",
        type: "post",
        data: {"recommendationName": document.getElementById("recommendationName").value,
            "recommendationPhone": document.getElementById("recommendationPhone").value},
        success: function (data) {
            if(data==3){
                alert("操作成功！");
                window.location.href = Feng.ctxPath + "/integralMallWeixin/memberRecommendation";
            } else if(data==1){
                alert("推荐人不能是自己！");
            } else if(data==2){
                alert("不能互为推荐人！");
            } else {
                alert("请输入正确的推荐人电话及姓名！");
            }
        },
        error: function (data) {
            window.location.href = Feng.ctxPath + "/integralMallWeixin/personalCenter";
        }
    });
};